package org.ccams.dao;

import java.sql.SQLException;
import java.util.List;

import org.ccams.domain.InsertHelp;
import org.ccams.domain.TSalesordersH;
import org.ccams.domain.TSalesordersHelp;
import org.ccams.util.PageParameter;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class TSalesordersHDAO extends SqlMapClientDaoSupport {
	
	//查询一段时间的销售信息
	@SuppressWarnings( { "unchecked", "deprecation" })
	public List<TSalesordersHelp> getTSalesordersHByDate(PageParameter page) {
		return getSqlMapClientTemplate().queryForList(
				"t_salesorders_h.getTSalesordersHByDate", page);
	}

	//查询一段时间的销售信息总数
	public int getSalesordersCountByDate() {
		int count = 0;
		count = (Integer) getSqlMapClientTemplate().queryForObject(
				"t_salesorders_h.getSalesordersCountByDate");
		return count;
	}

	public int insertSalesordersh(InsertHelp insertHelp) throws Exception {
		int i = 0;

		try {
			i = getSqlMapClientTemplate().update(
					"t_salesorders_h.abatorgenerated_insert", insertHelp);
		} catch (Exception ex) {
			ex.printStackTrace();
			throw ex;
		}
		return i;
	}

	public int updateByPrimaryKey(InsertHelp insertHelp) throws SQLException {
		return getSqlMapClientTemplate().update(
				"t_salesorders_h.abatorgenerated_update", insertHelp);
	}

	public TSalesordersH selectByPrimaryKey(Long idtSalesordersH)
			throws SQLException {
		return null;
	}

	public int deleteByPrimaryKey(String id) throws SQLException {
		return getSqlMapClientTemplate().delete(
				"t_salesorders_h.abatorgenerated_deleteByExample", id);

	}
	/**
	 * 获得最新id
	 * @return
	 */
	public int getNewId() {
		int count = 0;
		count = (Integer) getSqlMapClientTemplate().queryForObject(
				"t_salesorders_h.getNewId");
		return count;
	}
	/**
	 * 审核销售订单
	 * @return
	 */
	
	public int t_salesorders_hassess(String id) throws SQLException {
		return getSqlMapClientTemplate().delete(
				"t_salesorders_h.assess", id);

	}
	/**
	 *列出所有未采购的订单名户名称与订单号
	 *@return 
	 */
	@SuppressWarnings( { "unchecked", "deprecation" })
	public List<TSalesordersHelp> getTSalesordersHByOrderChecked() {
		return getSqlMapClientTemplate().queryForList(
				"t_salesorders_h.getTSalesordersHByOrderChecked");
	}	
}
